#include <assert.h>

#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "ADC_C_API/water_detector_sample/getdata.h"
//读取TDS
static napi_value gettds(napi_env env, napi_callback_info info) {
  napi_status status;
  napi_value tds_value;

  status = napi_create_int32(env, getTDS() , &tds_value);
  assert(status == napi_ok);
  return tds_value;
}
//读取TBS等级
static napi_value gettbs_level(napi_env env, napi_callback_info info) {
  napi_status status;
  napi_value tbs_level;

  status = napi_create_int32(env, getTBS_level() , &tbs_level);
  assert(status == napi_ok);
  return tbs_level;
}
//读取TBS值
static napi_value gettbs_value(napi_env env, napi_callback_info info) {
  napi_status status;
  napi_value tbs_value;

  status = napi_create_int32(env, getTBS_value() , &tbs_value);
  assert(status == napi_ok);
  return tbs_value;
}
//读取PH值
static napi_value getph(napi_env env, napi_callback_info info) {
  napi_status status;
  napi_value ph_value;

  status = napi_create_double(env, getPH() , &ph_value);
  assert(status == napi_ok);
  return ph_value;
}

static napi_value Init(napi_env env, napi_value exports) {
  napi_status status;
    napi_property_descriptor desc[] = {
        DECLARE_NAPI_FUNCTION("gettds", gettds),
        DECLARE_NAPI_FUNCTION("gettbs_level", gettbs_level),
        DECLARE_NAPI_FUNCTION("getph", getph),
        DECLARE_NAPI_FUNCTION("gettbs_value", gettbs_value),
    };
  status = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
  assert(status == napi_ok);
  return exports;
}

NAPI_MODULE(adc_sensor, Init)
